package pl.easyshop.core.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.springframework.security.core.GrantedAuthority;

/**
 * Group role/authority data model.
 * 
 * @author Pawel Witkowski
 */
@Entity
@Table (name="TBL_USER_GROUP_AUTHORITY", 
		uniqueConstraints={@UniqueConstraint(columnNames={"role", "group_id"})})
public class UserGroupAuthorityModel extends AbstractBaseModel implements GrantedAuthority {

	/** Unique serialization identifier. */
	private static final long serialVersionUID = 4928141360373703925L;

	/** Role/Authority code name. */
	@Column(name="role", length=64, nullable=false)
	private String role;
	
	/** Group. */
	@ManyToOne
	@JoinColumn(name = "GROUP_ID", nullable = false)
	private UserGroupModel group;
	
	@Override
	public String getAuthority() {
		return getRole();
	}
	
	/**
	 * Get role property value.
	 * @return the role
	 */
	public String getRole() {
		return role;
	}

	/**
	 * Set role property value.
	 * @param role the role to set
	 */
	public void setRole(String role) {
		this.role = role;
	}

	/**
	 * Get group property value.
	 * @return the group
	 */
	public UserGroupModel getGroup() {
		return group;
	}

	/**
	 * Set group property value.
	 * @param group the group to set
	 */
	public void setGroup(UserGroupModel group) {
		this.group = group;
	}

}
